home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume17 / calentool / part11 < prev    next >
Encoding:
Internet Message Format  |  1991-04-06  |  54.6 KB

  1. From: billr@saab.CNA.TEK.COM (Bill Randle)
  2. Newsgroups: comp.sources.misc
  3. Subject: v17i092:  calentool - day/week/month/year-at-a-glance SunView tool, Part11/23
  4. Message-ID: <1991Apr6.023939.17167@sparky.IMD.Sterling.COM>
  5. Date: 6 Apr 91 02:39:39 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 93c31ccb 2af5b8de 3f31ef26 671d2e8f
  8.  
  9. Submitted-by: Bill Randle <billr@saab.CNA.TEK.COM>
  10. Posting-number: Volume 17, Issue 92
  11. Archive-name: calentool/part11
  12.  
  13. #! /bin/sh
  14. # This is a shell archive.  Remove anything before this line, then unpack
  15. # it by saving it into a file and typing "sh file".  To overwrite existing
  16. # files, type "sh file -c".  You can also feed this as standard input via
  17. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  18. # will see the following message at the end:
  19. #        "End of archive 11 (of 23)."
  20. # Contents:  cal2ct.c dates/events expire.c tool.c
  21. # Wrapped by billr@saab on Thu Mar 28 08:38:22 1991
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'cal2ct.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'cal2ct.c'\"
  25. else
  26. echo shar: Extracting \"'cal2ct.c'\" \(11379 characters\)
  27. sed "s/^X//" >'cal2ct.c' <<'END_OF_FILE'
  28. X/*
  29. X * $Header: cal2ct.c,v 2.4 91/03/27 16:44:54 billr Exp $
  30. X */
  31. X/*
  32. X * cal2ct - convert calendar reminder files to calentool style files
  33. X *
  34. X * Author: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
  35. X *
  36. X * Copyright (C) 1989, 1991 Tektronix, Inc.  All Rights Reserved
  37. X *
  38. X * Permission is hereby granted to use and modify this code in source
  39. X * or binary form as long as it is not sold for profit and this copyright
  40. X * notice remains intact.
  41. X */
  42. X
  43. X#include "ct.h"
  44. X#include <stdio.h>
  45. X#include <ctype.h>
  46. X#include <sys/time.h>
  47. X
  48. Xstruct appt_entry appts, *aptr;
  49. Xchar filename[128], *file, *ofile;
  50. XFILE *fp;
  51. Xstruct tm current, start, today, *localtime();
  52. Xstruct timeval tp;
  53. Xint run_days = -1, use_date = 0;
  54. Xint day_first = FALSE;
  55. Xvoid err_rpt();
  56. X
  57. Xextern char *getenv();
  58. Xextern int optind;
  59. Xextern char *optarg;
  60. X
  61. Xmain(argc, argv)
  62. Xint argc;
  63. Xchar *argv[];
  64. X{
  65. X    int flag;
  66. X
  67. X    gettimeofday(&tp, NULL);
  68. X    current = today = *localtime(&tp.tv_sec);
  69. X    ofile = NULL;
  70. X    while ((flag = getopt(argc, argv, "d:f:r:eE")) != EOF)
  71. X        switch (flag) {
  72. X            case 'd':  /* starting date */
  73. X                /* updates "current" */
  74. X                (void)parse_date(optarg, TRUE);
  75. X                use_date++;
  76. X                break;
  77. X            case 'e':
  78. X            case 'E':  /* European style dates */
  79. X                day_first = TRUE;
  80. X                break;
  81. X            case 'f':  /* output file */
  82. X                ofile = optarg;
  83. X                break;
  84. X            case 'r':  /* number of days to process */
  85. X                run_days = atoi(optarg);
  86. X                break;
  87. X            default:  /* unknown option */
  88. X                fprintf(stderr, "usage: cal2ct [-d date] [-r days] [-e] [-f outfile] [file]\n");
  89. X                break;
  90. X        }
  91. X
  92. X    start = current;
  93. X    if (optind < argc)
  94. X        file = argv[optind];
  95. X    else {
  96. X        strcpy(filename, getenv("HOME"));
  97. X        strcat(filename, "/calendar");
  98. X        file = filename;
  99. X    }
  100. X
  101. X    if ((fp = fopen(file, "r")) == NULL) {
  102. X        fprintf(stderr, "can't open calendar file for reading\n");
  103. X        exit(1);
  104. X    }
  105. X    if (!read_cal_file()) {
  106. X        fprintf(stderr, "no reminders read from %s\n", file);
  107. X        exit(1);
  108. X    }
  109. X    fclose(fp);
  110. X    if (ofile)
  111. X        strcpy(filename, ofile);
  112. X    else {
  113. X        strcpy(filename, getenv("HOME"));
  114. X        strcat(filename, "/.appointments");
  115. X    }
  116. X    if ((fp = fopen(filename, "w")) == NULL) {
  117. X        fprintf(stderr, "can't open appointments file for writing\n");
  118. X        exit(1);
  119. X    }
  120. X    write_ct_file();
  121. X}
  122. X
  123. X/*
  124. X * read dates from calendar file and stuff into appts struct
  125. X */
  126. Xread_cal_file()
  127. X{
  128. X    char *fgets();
  129. X    char buf[512];
  130. X    struct appt_entry *optr;
  131. X
  132. X    aptr = &appts;
  133. X    while (fgets(buf, 512, fp) != NULL) {
  134. X        aptr->repeat = aptr->lookahead = 0;
  135. X        aptr->warn = 10;
  136. X        aptr->flags = A_NOTE;
  137. X        aptr->next = NULL;
  138. X        if (parse_cal_date(buf))
  139. X            continue;
  140. X        aptr->next = (struct appt_entry *)malloc(sizeof(struct appt_entry));
  141. X        if (aptr->next == NULL) {
  142. X            fprintf(stderr, "out of memory\n");
  143. X            return;
  144. X        }
  145. X        optr = aptr;
  146. X        aptr = aptr->next;
  147. X    }
  148. X    if (aptr == &appts)
  149. X        return(0);    /* nothing read */
  150. X    /* don't need the last one */
  151. X    free(aptr);
  152. X    optr->next = NULL;
  153. X    return(1);
  154. X}
  155. X
  156. X/*
  157. X * write out the new .appointments file
  158. X */
  159. Xwrite_ct_file()
  160. X{
  161. X    aptr = &appts;
  162. X    fputs(HEADER, fp);
  163. X    while (aptr) {
  164. X        if (put_aentry(fp, aptr)) {
  165. X            fprintf(stderr, "error writing appointments file\n");
  166. X            return;
  167. X        }
  168. X        aptr = aptr->next;
  169. X    }
  170. X}
  171. X
  172. Xchar *dayname[7] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
  173. Xchar *monthname[12] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
  174. X    "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
  175. X
  176. X/*
  177. X * parse the date in the buffer and reset the "current"
  178. X * date to reflect that date. The date may take the form of a
  179. X * month and day where the month may be spelled or numeric, e.g.:
  180. X * Feb 27, feb 27, 2/27. The month may be a `*' to refer to any
  181. X * month, e.g. "* 27" or "* /27".
  182. X * Limitation: the date is expected to start at the begining of
  183. X * the line. (calendar allows it anywhere in the line.)
  184. X */
  185. Xparse_cal_date(str)
  186. Xchar *str;
  187. X{
  188. X    char c[4];
  189. X    int i, m = -1, d = -1;
  190. X    void fix_current_day();
  191. X
  192. X    current = start;    /* start with this month, day, year */
  193. X    while (isspace(*str))
  194. X        ++str;
  195. X
  196. X    if (isdigit(*str)) {
  197. X        /* must be a m/d date */
  198. X        /* assume it's a month first */
  199. X        m = *str++ - '0';
  200. X        if (isdigit(*str))
  201. X            m = m*10 + *str++ - '0';
  202. X        --m; /* make it zero based */
  203. X        if (*str != '/') {
  204. X            /* no more chars => bad format */
  205. X            fprintf(stderr, "badly formed date: %s\n", str-2);
  206. X            return(1);
  207. X        } else {
  208. X            ++str;
  209. X            if (isdigit(*str)) {
  210. X                d = *str++ - '0';
  211. X                while (isdigit(*str))
  212. X                    d = d*10 + *str++ - '0';
  213. X            } else {
  214. X                fprintf(stderr, "badly formed date: %s\n", str-2);
  215. X                return(1);
  216. X            }
  217. X        }
  218. X    } else if (*str == '*') {
  219. X        aptr->flags |= ALL_MONTHS;
  220. X        ++str;
  221. X        while (isspace(*str) || *str == '/')
  222. X            ++str;
  223. X        d = *str++ - '0';
  224. X        while (isdigit(*str))
  225. X            d = d*10 + *str++ - '0';
  226. X    } else {
  227. X        /* month name */
  228. X        c[0] = islower(*str) ? toupper(*str) : *str;
  229. X        ++str;
  230. X        c[1] = islower(*str) ? toupper(*str) : *str;
  231. X        if (*++str) {
  232. X            c[2] = islower(*str) ? toupper(*str) : *str;
  233. X            c[3] = '\0';
  234. X        } else
  235. X            c[2] = '\0';
  236. X        while (!isspace(*str))
  237. X            ++str;
  238. X        /* check month names */
  239. X        for (i=0; i<12; i++) {
  240. X            if (!strcmp(c, monthname[i])) {
  241. X                m = i;
  242. X                break;;
  243. X            }
  244. X        }
  245. X        if (m >= 0) {
  246. X            /* match found */
  247. X            while (!isspace(*str))
  248. X                ++str;
  249. X            d = *++str - '0';
  250. X            ++str;
  251. X            while (isdigit(*str))
  252. X                d = d*10 + *str++ - '0';
  253. X        } else {
  254. X            fprintf(stderr, "badly formed date: %s\n", str-2);
  255. X            return(1);
  256. X        }
  257. X    }
  258. X    current.tm_mon = m;
  259. X    current.tm_mday = d;
  260. X    if (use_date || run_days >= 0) {
  261. X        if (!run_days) {
  262. X            if (ymd_compare(current, start) != 0)
  263. X                return(1);
  264. X        } else if (run_days > 0) {
  265. X            if (ymd_compare(current, start) >= 0) {
  266. X                struct tm Save;
  267. X
  268. X                Save = current;
  269. X                current = start;
  270. X                current.tm_mday += run_days;
  271. X                fix_current_day();
  272. X                if (ymd_compare(Save, current) > 0)
  273. X                    return(1);
  274. X                current = Save;
  275. X            } else
  276. X                return(1);
  277. X        } else if (ymd_compare(current, start) < 0)
  278. X            return(1);
  279. X    }
  280. X    while (isspace(*str))
  281. X        ++str;
  282. X    strcpy(aptr->str, str);
  283. X    aptr->year = current.tm_year;
  284. X    aptr->month = current.tm_mon;
  285. X    aptr->day = current.tm_mday;
  286. X    return(0);
  287. X}
  288. X
  289. X/*
  290. X *    Reset some values in current tm structure. Year, month and
  291. X *    day-of-month are valid but day and/or month may be < 0 or
  292. X *    greater than the maximum value, in which case they are adjusted
  293. X *    accordingly. Day-of-year and day-of-week are then recalculated.
  294. X */
  295. Xvoid
  296. Xfix_current_day()
  297. X{
  298. X    int month, totdays = 0;
  299. X    struct tm from, to;
  300. X
  301. X    if (current.tm_mon < JAN) {
  302. X        current.tm_mon = DEC;
  303. X        current.tm_year--;
  304. X    } else if (current.tm_mon > DEC) {
  305. X        current.tm_mon = JAN;
  306. X        current.tm_year++;
  307. X    }
  308. X    if (current.tm_mday < 1) {
  309. X        current.tm_mon--;
  310. X        if (current.tm_mon < JAN) {
  311. X            current.tm_mon = DEC;
  312. X            current.tm_year--;
  313. X        }
  314. X        current.tm_mday += monthlength(current.tm_mon);
  315. X    } else if (current.tm_mday > monthlength(current.tm_mon)) {
  316. X        current.tm_mday -= monthlength(current.tm_mon);
  317. X        current.tm_mon++;
  318. X        if (current.tm_mon > DEC) {
  319. X            current.tm_mon = JAN;
  320. X            current.tm_year++;
  321. X        }
  322. X    }
  323. X    current.tm_yday = current.tm_mday - 1;
  324. X    for (month = 0; month < current.tm_mon; month++) {
  325. X        current.tm_yday += monthlength(month);
  326. X    }
  327. X    if ((current.tm_year < today.tm_year)
  328. X        || ((current.tm_year == today.tm_year)
  329. X        && (current.tm_yday < today.tm_yday))) {
  330. X        from = current;
  331. X        to = today;
  332. X    } else {
  333. X        from = today;
  334. X        to = current;
  335. X    }
  336. X    if (from.tm_year != to.tm_year) {
  337. X        for (totdays = 0; from.tm_year < to.tm_year; from.tm_year++)
  338. X            totdays += dysize(from.tm_year + 1900);
  339. X    }
  340. X    totdays += to.tm_yday - from.tm_yday;
  341. X    if ((current.tm_year < today.tm_year)
  342. X        || ((current.tm_year == today.tm_year)
  343. X        && (current.tm_yday < today.tm_yday)))
  344. X        totdays = -totdays;
  345. X    current.tm_wday =
  346. X        ((totdays % 7) + 7 + today.tm_wday) % 7;
  347. X}
  348. X
  349. Xint
  350. Xmonthlength(month)
  351. Xint    month;
  352. X{
  353. X    static int    monthlengths[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  354. X
  355. X    if (month == FEB && (dysize(current.tm_year + 1900) == 366))
  356. X        return(29);
  357. X    else
  358. X        return(monthlengths[month]);
  359. X}
  360. X
  361. X/*
  362. X * Compares two sets of year/month/day.  Returns -1 if the first is earlier than
  363. X * the second, +1 if later, 0 if they are the same.
  364. X */
  365. Xymd_compare(day0, day1)
  366. Xstruct tm day0, day1;
  367. X{
  368. X        if (day0.tm_year > day1.tm_year) return(1);
  369. X        if (day0.tm_year < day1.tm_year) return(-1);
  370. X        if (day0.tm_mon > day1.tm_mon) return(1);
  371. X        if (day0.tm_mon < day1.tm_mon) return(-1);
  372. X        if (day0.tm_mday > day1.tm_mday) return(1);
  373. X        if (day0.tm_mday < day1.tm_mday) return(-1);
  374. X        return(0);
  375. X}
  376. X
  377. X/*
  378. X * parse the date on the given string and reset the "current"
  379. X * date to reflect that date. The date may take the form of a
  380. X * day name (e.g. Tu, Tue, Tuesday) or a date in m/d/y format
  381. X * where the month and/or year may be missing (e.g. 27 = 27th
  382. X * of this month, 8/27 = August 27 of this year, 8/27/89 =
  383. X * August 27 of 1989. If 'cmdline' is true, then the string
  384. X * came from the command line '-d' option.
  385. X * If the first character of the date is + or - scan the number and
  386. X * use it as an offset in days from the current date.  Thus -1 becomes
  387. X * yesterday and +1 becomes tomorrow. pbm.
  388. X */
  389. Xint
  390. Xparse_date(str, cmdline)
  391. Xchar *str;
  392. Xint cmdline;
  393. X{
  394. X    char c[4];
  395. X    int i, dow = -1, m = -1, d = -1, y = -1;
  396. X
  397. X    if (isdigit(*str)) {
  398. X        /* must be a m/d/y date */
  399. X        /* assume it's a month first */
  400. X        m = *str++ - '0';
  401. X        if (isdigit(*str))
  402. X            m = m*10 + *str++ - '0';
  403. X        if (!*str) {
  404. X            /* no more chars => day only */
  405. X            d = m;
  406. X            m = -1;
  407. X        } else if (*str++ != '/') {
  408. X            if (cmdline)
  409. X                err_rpt("badly formed date for -d option (ignored)", NON_FATAL);
  410. X            else
  411. X                err_rpt("badly formed date - please reenter", NON_FATAL);
  412. X            return(1);
  413. X        } else {
  414. X            d = *str++ - '0';
  415. X            if (isdigit(*str))
  416. X                d = d*10 + *str++ - '0';
  417. X            if (*str++ == '/') {
  418. X                /* year also specified */
  419. X                y = *str++ - '0';
  420. X                if (isdigit(*str)) {
  421. X                    y = y*10 + *str++ - '0';
  422. X                    if (*str && isdigit(*str))
  423. X                        y = y*10 + *str++ - '0';
  424. X                    if (*str && isdigit(*str))
  425. X                        y = y*10 + *str++ - '0';
  426. X                }
  427. X            }
  428. X        }
  429. X        if (y > 0) {
  430. X            if (y > 1900)
  431. X                y -= 1900;
  432. X            current.tm_year = y;
  433. X        }
  434. X        if (day_first) {
  435. X            if (m > 0) {
  436. X                current.tm_mon = d - 1;
  437. X                current.tm_mday = m;
  438. X            } else if (d > 0)
  439. X                current.tm_mday = d;
  440. X        } else {
  441. X            if (m > 0) {
  442. X                current.tm_mon = m - 1;
  443. X                current.tm_mday = d;
  444. X            } else if (d > 0)
  445. X                current.tm_mday = d;
  446. X        }
  447. X        fix_current_day();
  448. X    } else if (*str == '-' || *str == '+') {
  449. X        /*
  450. X         * If the argument begins with a + or - assume that it is an
  451. X         * offset in days from the current date. Use current date if the
  452. X         * number doesn't scan after the - or +. pbm
  453. X         */
  454. X        if (sscanf(str, "%d", &i) == 1) {
  455. X            current.tm_mday += i;
  456. X            fix_current_day();
  457. X        }
  458. X    } else {
  459. X        /* day of week */
  460. X        /* check for day names */
  461. X        c[0] = islower(*str) ? toupper(*str) : *str;
  462. X        ++str;
  463. X        c[1] = islower(*str) ? toupper(*str) : *str;
  464. X        if (*++str) {
  465. X            c[2] = islower(*str) ? toupper(*str) : *str;
  466. X            c[3] = '\0';
  467. X        } else
  468. X            c[2] = '\0';
  469. X        for (i=0; i<7; i++) {
  470. X            if (!strncmp(c, dayname[i], 2)) {
  471. X                dow = i;
  472. X                break;
  473. X            }
  474. X        }
  475. X        if (dow >= 0) {
  476. X            /* match found */
  477. X            current.tm_mday += dow - current.tm_wday;
  478. X            fix_current_day();
  479. X        } else if (!strcmp(c, "TOM")) {
  480. X            /* tommorrow */
  481. X            current.tm_mday++;
  482. X            fix_current_day();
  483. X        } else if (!strcmp(c, "YES")) {
  484. X            /* yesterday */
  485. X            current.tm_mday--;
  486. X            fix_current_day();
  487. X        } else if (strcmp(c, "TOD")) {
  488. X            if (cmdline)
  489. X                err_rpt("badly formed date for -d option (ignored)", NON_FATAL);
  490. X            else
  491. X                err_rpt("badly formed date - please reenter", NON_FATAL);
  492. X            return(1);
  493. X        }
  494. X    }
  495. X    return(0);
  496. X}
  497. X
  498. Xvoid
  499. Xerr_rpt(str, flag)
  500. Xchar *str;
  501. Xint flag;
  502. X{
  503. X    fprintf(stderr, "%s\n", str);
  504. X    if (flag == FATAL)
  505. X        exit(1);
  506. X}
  507. END_OF_FILE
  508. if test 11379 -ne `wc -c <'cal2ct.c'`; then
  509.     echo shar: \"'cal2ct.c'\" unpacked with wrong size!
  510. fi
  511. # end of 'cal2ct.c'
  512. fi
  513. if test -f 'dates/events' -a "${1}" != "-c" ; then 
  514.   echo shar: Will not clobber existing file \"'dates/events'\"
  515. else
  516. echo shar: Extracting \"'dates/events'\" \(288 characters\)
  517. sed "s/^X//" >'dates/events' <<'END_OF_FILE'
  518. X# CalenTool V2.2 - nflag=1 range=1,12  - DO NOT REMOVE THIS LINE
  519. X# $Header: events,v 1.1 91/03/07 16:19:02 billr Exp $
  520. X# Common include file just includes individual parts
  521. X#
  522. X#include <events1>
  523. X#include <events2>
  524. X#include <events3>
  525. X#include <events4>
  526. X#include <events5>
  527. X#include <events6>
  528. END_OF_FILE
  529. if test 288 -ne `wc -c <'dates/events'`; then
  530.     echo shar: \"'dates/events'\" unpacked with wrong size!
  531. fi
  532. # end of 'dates/events'
  533. fi
  534. if test -f 'expire.c' -a "${1}" != "-c" ; then 
  535.   echo shar: Will not clobber existing file \"'expire.c'\"
  536. else
  537. echo shar: Extracting \"'expire.c'\" \(5720 characters\)
  538. sed "s/^X//" >'expire.c' <<'END_OF_FILE'
  539. X/*
  540. X * $Header: expire.c,v 2.3 91/03/27 16:45:39 billr Exp $
  541. X *
  542. X * expire.c
  543. X * expire outdated appts, i.e. remove them from the appts file, if they
  544. X * are older than <n> days and store them in .appointmentYY if <save_old>.
  545. X *
  546. X * Copyright (C) 1989, 1991 Tektronix, Inc.
  547. X *    All Rights Reserved
  548. X * Permission is hereby granted to use and modify this code in source
  549. X * or binary form as long as it is not sold for profit and this copyright
  550. X * notice remains intact.
  551. X */
  552. X
  553. X#include <stdio.h>
  554. X#include <sys/time.h>
  555. X#include <sys/types.h>
  556. X#include <sys/stat.h>
  557. X#include <sys/errno.h>
  558. X#include "ct.h"
  559. X
  560. Xextern struct tm today,current;
  561. Xextern char apts_pathname[], tmpapts_pathname[];
  562. Xextern char inbuf[], apts_dir[];
  563. Xextern int save_old,read_only;
  564. Xextern int errno;
  565. Xextern double julian_day();
  566. Xextern double nth_mday_of_month();
  567. X
  568. X/*
  569. X * Scan appointments file for outdated appointments. If <save_old> is
  570. X * TRUE then save them to a special file of the form ".appointments.YY",
  571. X * where YY is the year of that appointment.  Outdated appointments are
  572. X * appointments that are older that <edays> old.  If <edays> is zero then
  573. X * Outdated appointments are appointments from previous years. If <save_old>
  574. X * is not set, then Outdated appointments are just deleted.
  575. X * Setting <save_old> TRUE (-o) and <edays> to 0 (-x 0) gives the behavior
  576. X * described by the "-o" switch.
  577. X */
  578. Xexpire(edays)
  579. Xint edays;
  580. X{
  581. X    FILE *apts, *temp_apts, *fp;
  582. X    int read_stat;
  583. X    int runl, week;
  584. X    char save_file[128];
  585. X    struct appt_entry appt;
  586. X    struct stat sbuf;
  587. X    struct tm savecurrent;
  588. X    int successful = 1;    /* assume this worked */
  589. X
  590. X    /*
  591. X     * method: for each regular appt in the file (or limited
  592. X     * duration appt), compare the Julian date of that appt
  593. X     * and the Julian date of today, looking for a difference
  594. X     * greater than <edays>.
  595. X     */
  596. X    if (read_only) /* we can't expire from a calendar if read_only */
  597. X        return;
  598. X    if ((apts = fopen(apts_pathname, "r")) == NULL)
  599. X        successful = err_rpt("can't open appointments file, aborting expire", NON_FATAL);
  600. X    if ((temp_apts = fopen(tmpapts_pathname, "w")) == NULL)
  601. X        successful = err_rpt("can't open temp file for writing, aborting expire", NON_FATAL);
  602. X    /*
  603. X     * now go thru the appointments file
  604. X     */
  605. X    savecurrent = current;  /* save so can restore after loop */
  606. X    while (successful && (read_stat=get_aentry(apts, &appt, TRUE, 0, 0)) != EOF) {
  607. X        if (read_stat)
  608. X            continue;    /* read error (ignore) */
  609. X        if (appt.flags & A_COMMENT) {
  610. X            fputs(inbuf, temp_apts);
  611. X            continue;
  612. X        }
  613. X        current.tm_year = appt.year;
  614. X        current.tm_mon = appt.month;
  615. X        current.tm_mday = appt.day;
  616. X        if (appt.flags & ALL_YEARS)
  617. X            /* force this to be saved */
  618. X            current.tm_year = today.tm_year + 1;
  619. X        if (appt.flags & ALL_MONTHS)
  620. X            /* maybe saved, pick worse case */
  621. X            current.tm_mon = DEC;
  622. X        if (appt.flags & ALL_DAYS || appt.flags & EVERY_MON_FRI) {
  623. X            if (current.tm_year < today.tm_year ||
  624. X               (current.tm_year == today.tm_year &&
  625. X                current.tm_mon < today.tm_mon)) {
  626. X                /* maybe saved, pick worse case */
  627. X                current.tm_mday = monthlength(current.tm_mon);
  628. X                fix_current_day();
  629. X                if (appt.flags & EVERY_MON_FRI)
  630. X                    while (current.tm_wday == SAT
  631. X                        || current.tm_wday == SUN) {
  632. X                        current.tm_mday--;
  633. X                        fix_current_day();
  634. X                    }
  635. X            }
  636. X        }
  637. X        if (appt.flags & EVERY_SOMEDAY) {
  638. X            if ((appt.repeat & ALL_WEEKS) == ALL_WEEKS || appt.repeat & LAST_WEEK ||
  639. X                appt.repeat & WEEK5)
  640. X                week = 5;
  641. X            else if (appt.repeat & WEEK4)
  642. X                week = 4;
  643. X            else if (appt.repeat & WEEK3)
  644. X                week = 3;
  645. X            else if (appt.repeat & WEEK2)
  646. X                week = 2;
  647. X            else if (appt.repeat & WEEK1)
  648. X                week = 1;
  649. X            current.tm_mday = (int)nth_mday_of_month(week, Pickday(appt.flags), current.tm_mon, current.tm_year+1900);
  650. X            if (current.tm_mday > monthlength(current.tm_mon))
  651. X                current.tm_mday = (int)nth_mday_of_month(week-1, Pickday(appt.flags), current.tm_mon, current.tm_year+1900);
  652. X            if (appt.flags & RUN) {
  653. X                current.tm_mday += appt.runlength;
  654. X                fix_current_day();
  655. X            }
  656. X        } else if (appt.flags & REPEAT) {
  657. X            if (appt.flags & RUN)
  658. X                runl = appt.runlength;
  659. X            else
  660. X                runl = 1;
  661. X            while (ymd_compare(current, today) < 0 && runl) {
  662. X                if (appt.flags & RUN)
  663. X                    --runl;
  664. X                if (runl) {
  665. X                    current.tm_mday += appt.repeat;
  666. X                    fix_current_day();
  667. X                }
  668. X            }
  669. X        }
  670. X        current.tm_mday += edays;  /* offset by expire days */
  671. X        fix_current_day();
  672. X        if (((edays == 0) && (current.tm_year >= today.tm_year)) ||
  673. X            julian_day((double)current.tm_mday, current.tm_mon, current.tm_year+1900) >=
  674. X            julian_day((double)today.tm_mday, today.tm_mon, today.tm_year+1900)) {
  675. X            if (put_aentry(temp_apts, &appt)) {
  676. X                /* write error */
  677. X                break;
  678. X            }
  679. X        } else {
  680. X            if (save_old) {
  681. X                /* prepend directory info */
  682. X                sprintf(save_file, "%s.%02d",
  683. X                    apts_pathname, appt.year);
  684. X                if (stat(save_file, &sbuf) && errno == ENOENT) {
  685. X                    /* new file*/
  686. X                    if ((fp = fopen(save_file, "w")) == NULL)
  687. X                        successful = err_rpt("can't open save file, aborting expire", NON_FATAL);
  688. X                    fputs(HEADER, fp);
  689. X                    fclose(fp);
  690. X                }
  691. X                if ((fp = fopen(save_file, "a+")) == NULL)
  692. X                    successful = err_rpt("can't open save file, aborting expire", NON_FATAL);
  693. X                else {
  694. X                    if (put_aentry(fp, &appt))
  695. X                        successful = err_rpt("write to save appt file failed, aborting expire", NON_FATAL);
  696. X                    fclose(fp);
  697. X                }
  698. X            }
  699. X        }
  700. X        }
  701. X    if (ferror(temp_apts))
  702. X        successful = err_rpt("write on temp file failed", NON_FATAL);
  703. X    fclose(temp_apts);
  704. X        fclose(apts);
  705. X    current = savecurrent;   /* restore current from temp */
  706. X    /* don't rename zero length files */
  707. X    stat(tmpapts_pathname, &sbuf);
  708. X    if (sbuf.st_size == (off_t) 0)
  709. X        err_rpt("zero length temp file - not renamed", NON_FATAL);
  710. X    else if (successful)
  711. X        xrename(tmpapts_pathname, apts_pathname);
  712. X}
  713. X
  714. END_OF_FILE
  715. if test 5720 -ne `wc -c <'expire.c'`; then
  716.     echo shar: \"'expire.c'\" unpacked with wrong size!
  717. fi
  718. # end of 'expire.c'
  719. fi
  720. if test -f 'tool.c' -a "${1}" != "-c" ; then 
  721.   echo shar: Will not clobber existing file \"'tool.c'\"
  722. else
  723. echo shar: Extracting \"'tool.c'\" \(33530 characters\)
  724. sed "s/^X//" >'tool.c' <<'END_OF_FILE'
  725. X/*
  726. X * $Header: tool.c,v 2.5 91/03/27 16:46:32 billr Exp $
  727. X */
  728. X/*
  729. X * tool.c
  730. X *
  731. X * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
  732. X *
  733. X * Original source Copyright (C) 1987, Sun Microsystems, Inc.
  734. X *    All Rights Reserved
  735. X * Permission is hereby granted to use and modify this program in source
  736. X * or binary form as long as it is not sold for profit and this copyright
  737. X * notice remains intact.
  738. X *
  739. X *
  740. X * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
  741. X *
  742. X * Changes and additions Copyright (C) 1988, 1989, 1991 Tektronix, Inc.
  743. X *    All Rights Reserved
  744. X * Permission is hereby granted to use and modify the modifications in source
  745. X * or binary form as long as they are not sold for profit and this copyright
  746. X * notice remains intact.
  747. X */
  748. X#include <stdio.h>    /* for NULL */
  749. X#include <suntool/sunview.h>
  750. X#include <suntool/canvas.h>
  751. X#include <suntool/panel.h>
  752. X#include <sunwindow/defaults.h>
  753. X#include <sys/file.h>
  754. X#include "ct.h"
  755. X
  756. X/*
  757. X * define standard B/W monochrome colors as defaults in case we're running
  758. X * on a color system with the monochrome colors set differently
  759. X */
  760. X#define FG_DEFAULT  { 0, 0, 0 }     /* black */
  761. X#define BG_DEFAULT  { 255, 255, 255 }   /* white */
  762. X
  763. Xextern int monday_first;
  764. Xextern struct tm current;
  765. Xextern Frame frame;
  766. Xextern int working_msg;
  767. Xextern int n_slots;
  768. Xextern int user_font;
  769. XCanvas canvas;
  770. XPanel panel;
  771. XPanel_item todaybutton_pi, working_pi;
  772. XPanel_item monthmenu_pi, yearmenu_pi, weekbutton_pi, daybutton_pi;
  773. XPanel_item previous_pi, next_pi, current_pi, filebutton_pi;
  774. XPanel_item clock_pi;
  775. XPanel_item runl_pi;
  776. XPanel_item donebutton_pi;
  777. X#ifndef NO_PRINTER
  778. XPanel_item printbutton_pi;
  779. X#endif
  780. X#ifndef NO_SUN_MOON
  781. XPanel_item moonbutton_pi, sunbutton_pi;
  782. X#endif
  783. XMenu next_menu, previous_menu;
  784. XMenu day_menu, week_menu, month_menu, year_menu;
  785. XMenu day_sel_menu, current_menu;
  786. XMenu done_menu;
  787. X#ifndef NO_PRINTER
  788. XMenu print_menu;
  789. X#endif
  790. XPixfont *font, *bigfont, *sfont;
  791. XFrame fframe = 0;
  792. XPanel fpanel, fcpanel;
  793. XFrame attr_frame;
  794. XPanel attr_panel;
  795. XPanel_item repeat_pi, remind_pi, everyx_pi, whichwk_pi, marked_pi;
  796. XPanel_item advw_pi;
  797. XFrame del_frame;
  798. XPanel del_panel;
  799. XPanel_item del_choice_pi;
  800. XFrame wmore_frame;
  801. XPanel wmore_panel;
  802. X#ifndef NO_SUN_MOON
  803. XFrame sframe = 0, mframe = 0;
  804. X#endif
  805. XFrame fileframe;
  806. XPanel filepanel;
  807. XPanel_item filename_pi, file_ro_pi;
  808. X#ifndef NO_PRINTER
  809. XPanel_item prcmd_pi;
  810. XPanel_item prfile_pi;
  811. Xint print_to_file = 0;
  812. XFrame prframe;
  813. X#endif
  814. X#ifndef NO_SUN_MOON
  815. XCanvas scanvas, mcanvas;
  816. XPanel_item sdate_pi, mdate_pi;
  817. Xstatic struct singlecolor       fg_default = FG_DEFAULT;
  818. Xstatic struct singlecolor       bg_default = BG_DEFAULT;
  819. X#endif
  820. XFrame prompt_frame = 0;
  821. XPixrect *morebutton;
  822. Xstatic Cursor panel_cursor, canvas_cursor;
  823. XFrame date_frame;
  824. XPanel_item setdate_pi;
  825. XFrame cut_frame;
  826. XPanel cut_panel;
  827. Xvoid monthmenu_notify(), yearmenu_notify(), weekbutton_notify();
  828. Xvoid month_menu_event(), year_menu_event(), week_menu_event();
  829. Xvoid todaybutton_notify(), currentbutton_notify(), daybutton_notify();
  830. Xvoid filebutton_notify(), current_menu_event();
  831. Xvoid cut_done(), cut_abort();
  832. Xvoid donebutton_notify(), done_menu_event();
  833. X#ifndef NO_SUN_MOON
  834. Xvoid moonbutton_notify(), sunbutton_notify();
  835. X#endif
  836. X#ifndef NO_PRINTER
  837. Xvoid printbutton_notify(), print_menu_event();
  838. X#endif
  839. Xvoid day_menu_event();
  840. Xvoid mainsw_selected();
  841. Xvoid next_menu_event(), nextbutton_notify();
  842. Xvoid previous_menu_event(), previous_menu_notify();
  843. Xvoid mainsw_inputevent();
  844. Xvoid fdone_proc(), fkeep_proc(), fappt_notify();
  845. Xvoid attr_accept(), attr_abort();
  846. Xvoid del_done();
  847. X#ifndef NO_SUN_MOON
  848. Xvoid sdone_proc(), mdone_proc();
  849. Xvoid sframe_done(), mframe_done();
  850. X#endif
  851. Xvoid fileframe_done(), file_accept(), file_reset(), file_done();
  852. Xvoid file_save();
  853. Xvoid prompt_no_notify(), prompt_yes_notify();
  854. Xvoid error_event(), file_orig();
  855. Xvoid dtframe_done(), dtdone_proc();
  856. X#ifndef NO_PRINTER
  857. Xvoid prframe_done(), prdone_proc();
  858. X#endif
  859. XNotify_value check_close();
  860. Xint monthlength();
  861. Xchar year_str[NR_YEARS][5]; /* holds strings for year menu */
  862. Xextern Pixwin *main_pixwin;
  863. Xextern Cursor day_cursor, wait_cursor;
  864. Xextern int day_is_open, mainsw_state;
  865. Xextern char clockstr[];
  866. Xextern struct appt_entry future[];
  867. Xextern int findex;
  868. Xextern struct dayslot *slots;
  869. X#ifndef NO_SUN_MOON
  870. Xextern Pixrect moon_icon_pr, sun_icon_pr;
  871. X#endif
  872. Xextern char printer[];
  873. Xextern int day_first;
  874. Xextern int locked;
  875. X
  876. X/* Create and init control panel */
  877. Xcreate_panel()
  878. X{
  879. X    int    width;
  880. X
  881. X    /* Create the control panel. */
  882. X    panel = window_create(frame, PANEL,
  883. X              WIN_HEIGHT, 72, WIN_FONT, font,
  884. X              WIN_CONSUME_KBD_EVENTS,
  885. X              WIN_UP_EVENTS, KEY_LEFT(7), 0,
  886. X              WIN_ERROR_MSG, "Can't create main panel.",
  887. X              0);
  888. X
  889. X    /* Create the panel items and their menus */
  890. X    done_menu = menu_create(MENU_STRINGS,
  891. X            "Close to Icon", "Quit Tool", 0,
  892. X            0);
  893. X
  894. X    donebutton_pi = panel_create_item(panel, PANEL_BUTTON,
  895. X                        PANEL_LABEL_IMAGE, 
  896. X                          panel_button_image(panel, "Done", 4, font),
  897. X            PANEL_EVENT_PROC, done_menu_event,
  898. X                        PANEL_NOTIFY_PROC, donebutton_notify,
  899. X            PANEL_ITEM_X, ATTR_COL(0),
  900. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  901. X                        0);
  902. X    
  903. X    if( monday_first ) 
  904. X        day_menu = menu_create(MENU_STRINGS, 
  905. X                    "Monday", "Tuesday", "Wednesday",
  906. X            "Thursday", "Friday", "Saturday", "Sunday", 0,
  907. X            0);
  908. X    else
  909. X        day_menu = menu_create(MENU_STRINGS, 
  910. X                    "Sunday", "Monday", "Tuesday", "Wednesday",
  911. X            "Thursday", "Friday", "Saturday", 0,
  912. X            0);
  913. X
  914. X    daybutton_pi = panel_create_item(panel, PANEL_BUTTON,
  915. X                        PANEL_LABEL_IMAGE, 
  916. X                          panel_button_image(panel, "Day", 3, font),
  917. X            PANEL_EVENT_PROC, day_menu_event,
  918. X                        PANEL_NOTIFY_PROC, daybutton_notify,
  919. X            PANEL_ITEM_X, ATTR_COL(7),
  920. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  921. X                        0);
  922. X    
  923. X    week_menu = menu_create(MENU_STRINGS, "1st", "2nd",
  924. X            "3rd", "4th", "5th", "Last", 0,
  925. X            0);
  926. X
  927. X    weekbutton_pi = panel_create_item(panel, PANEL_BUTTON,
  928. X                        PANEL_LABEL_IMAGE, 
  929. X                          panel_button_image(panel, "Week", 4, font),
  930. X            PANEL_EVENT_PROC, week_menu_event,
  931. X                        PANEL_NOTIFY_PROC, weekbutton_notify,
  932. X            PANEL_ITEM_X, ATTR_COL(12),
  933. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  934. X                        0);
  935. X
  936. X    month_menu = menu_create(MENU_STRINGS,
  937. X            "January", "February","March",
  938. X            "April", "May", "June", "July", "August",
  939. X            "September", "October", "November", "December", 0,
  940. X            0);
  941. X
  942. X    monthmenu_pi = panel_create_item(panel, PANEL_BUTTON,  
  943. X                        PANEL_LABEL_IMAGE,
  944. X              panel_button_image(panel, "Month", 5, font),
  945. X            PANEL_EVENT_PROC, month_menu_event,
  946. X                        PANEL_NOTIFY_PROC, monthmenu_notify,  
  947. X            PANEL_ITEM_X, ATTR_COL(18),
  948. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  949. X                        0);
  950. X
  951. X    year_menu = menu_create(0);    /* years filled in later */
  952. X    add_years_to_menu();
  953. X
  954. X    yearmenu_pi = panel_create_item(panel, PANEL_BUTTON,
  955. X                        PANEL_LABEL_IMAGE,
  956. X              panel_button_image(panel, "Year", 4, font),
  957. X            PANEL_EVENT_PROC, year_menu_event,
  958. X                        PANEL_NOTIFY_PROC, yearmenu_notify,
  959. X            PANEL_ITEM_X, ATTR_COL(25),
  960. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  961. X                        0);
  962. X
  963. X    todaybutton_pi = panel_create_item(panel, PANEL_BUTTON,
  964. X                        PANEL_LABEL_IMAGE, 
  965. X                          panel_button_image(panel, "Today", 5, font),
  966. X                        PANEL_NOTIFY_PROC, todaybutton_notify,
  967. X            PANEL_ITEM_X, ATTR_COL(34),
  968. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  969. X                        0);
  970. X
  971. X    filebutton_pi = panel_create_item(panel, PANEL_BUTTON,
  972. X                        PANEL_LABEL_IMAGE, 
  973. X                          panel_button_image(panel, "File", 4, font),
  974. X                        PANEL_NOTIFY_PROC, filebutton_notify,
  975. X            PANEL_ITEM_X, ATTR_COL(45),
  976. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  977. X                        0);
  978. X
  979. X#ifndef NO_PRINTER
  980. X    printbutton_pi = panel_create_item(panel, PANEL_BUTTON,
  981. X                        PANEL_LABEL_IMAGE, 
  982. X                          panel_button_image(panel, "Print", 5, font),
  983. X                        PANEL_EVENT_PROC, print_menu_event,
  984. X                        PANEL_NOTIFY_PROC, printbutton_notify,
  985. X            PANEL_ITEM_X, ATTR_COL(53),
  986. X            PANEL_ITEM_Y, ATTR_ROW(0)+2,
  987. X            PANEL_SHOW_ITEM, FALSE,
  988. X                        0);
  989. X    
  990. X    print_menu = menu_create(MENU_STRINGS, "Print Postscript", "Print Raster",
  991. X            "Change Printer", 0,
  992. X            0);
  993. X#endif
  994. X
  995. X    working_pi = panel_create_item(panel, PANEL_MESSAGE,
  996. X            PANEL_LABEL_STRING, "Working!",
  997. X            PANEL_LABEL_FONT, font,
  998. X            PANEL_LABEL_BOLD, TRUE,
  999. X            PANEL_SHOW_ITEM, FALSE,
  1000. X            PANEL_ITEM_X, ATTR_COL(37),
  1001. X            PANEL_ITEM_Y, ATTR_ROW(1)+5,
  1002. X            0);
  1003. X
  1004. X    previous_menu = menu_create(MENU_STRINGS,
  1005. X            "Yesterday", "Last Week", "Last Month", "Last Year", 0,
  1006. X            0);
  1007. X    
  1008. X    previous_pi = panel_create_item(panel, PANEL_BUTTON,
  1009. X                        PANEL_LABEL_IMAGE, 
  1010. X                          panel_button_image(panel, "Previous", 8, font),
  1011. X            PANEL_EVENT_PROC, previous_menu_event,
  1012. X                        PANEL_NOTIFY_PROC, previous_menu_notify, 
  1013. X            PANEL_ITEM_X, ATTR_COL(2),
  1014. X            PANEL_ITEM_Y, ATTR_ROW(2)-2,
  1015. X            0);
  1016. X
  1017. X    current_menu = menu_create(MENU_STRINGS, "Current Day",
  1018. X            "Current Week", "Current Month", "Current Year",
  1019. X            "Change Date", 0,
  1020. X            0);
  1021. X
  1022. X    current_pi = panel_create_item(panel, PANEL_BUTTON,
  1023. X                        PANEL_LABEL_IMAGE, 
  1024. X                          panel_button_image(panel, "Current", 7, font),
  1025. X            PANEL_EVENT_PROC, current_menu_event,
  1026. X                        PANEL_NOTIFY_PROC, currentbutton_notify,
  1027. X            PANEL_ITEM_X, ATTR_COL(13),
  1028. X            PANEL_ITEM_Y, ATTR_ROW(2)-2,
  1029. X                        0);
  1030. X
  1031. X    next_menu = menu_create(MENU_STRINGS, "Tomorrow",
  1032. X            "Next Week", "Next Month", "Next Year", 0,
  1033. X            0);
  1034. X    
  1035. X    next_pi = panel_create_item(panel, PANEL_BUTTON,
  1036. X                        PANEL_LABEL_IMAGE, 
  1037. X                          panel_button_image(panel, "Next", 4, font),
  1038. X            PANEL_EVENT_PROC, next_menu_event,
  1039. X                        PANEL_NOTIFY_PROC, nextbutton_notify, 
  1040. X            PANEL_ITEM_X, ATTR_COL(23),
  1041. X            PANEL_ITEM_Y, ATTR_ROW(2)-2,
  1042. X            0);
  1043. X
  1044. X    width = (int)window_get(panel, WIN_WIDTH);
  1045. X
  1046. X    get_today();    /* get current date and time */
  1047. X    clock_pi = panel_create_item(panel, PANEL_MESSAGE,
  1048. X            PANEL_ITEM_X, width-150-(strlen(clockstr)*font->pf_defaultsize.x),
  1049. X            PANEL_ITEM_Y, ATTR_ROW(2)+3,
  1050. X            PANEL_LABEL_STRING, clockstr,
  1051. X            PANEL_LABEL_FONT, font,
  1052. X            0);
  1053. X
  1054. X#ifndef NO_SUN_MOON
  1055. X    sunbutton_pi = panel_create_item(panel, PANEL_BUTTON,
  1056. X                        PANEL_LABEL_IMAGE, &sun_icon_pr,
  1057. X                        PANEL_NOTIFY_PROC, sunbutton_notify,
  1058. X            PANEL_ITEM_X, width-140,
  1059. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1060. X            PANEL_SHOW_ITEM, FALSE,
  1061. X                        0);
  1062. X
  1063. X    moonbutton_pi = panel_create_item(panel, PANEL_BUTTON,
  1064. X                        PANEL_LABEL_IMAGE, &moon_icon_pr,
  1065. X                        PANEL_NOTIFY_PROC, moonbutton_notify,
  1066. X            PANEL_ITEM_X, width-70,
  1067. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1068. X            PANEL_SHOW_ITEM, FALSE,
  1069. X                        0);
  1070. X#endif
  1071. X
  1072. X    /*
  1073. X     * menu strings for right MB menu in the canvas
  1074. X     * (day display). NB: if the order of this menu is
  1075. X     * changed, also change the #defines in ct.h
  1076. X     * (MMODIFY, MCUT, etc.).
  1077. X     */
  1078. X    day_sel_menu = menu_create(MENU_STRINGS,
  1079. X            "Modify", "Cut", "Paste", "Copy", "Delete",
  1080. X            "Undelete", 0,
  1081. X            0);
  1082. X
  1083. X    /*
  1084. X     * this button is displayed in the canvas, but needs a panel
  1085. X     * for the function call to work properly
  1086. X     */
  1087. X    morebutton = panel_button_image(panel, "More", 4, font);
  1088. X
  1089. X    /*
  1090. X     * interpose on panel events to check for L7 (open/close)
  1091. X     */
  1092. X    notify_interpose_event_func(panel, check_close, NOTIFY_SAFE);
  1093. X}
  1094. X
  1095. X/*
  1096. X * Add year strings to year panel menu
  1097. X */
  1098. Xadd_years_to_menu()
  1099. X{
  1100. X    int n, year;
  1101. X
  1102. X    n = 1;
  1103. X    for (year=START_YEAR; year<START_YEAR+NR_YEARS; year++,n++) {
  1104. X        sprintf(year_str[n-1], "%4d", year+1900);
  1105. X        menu_set(year_menu, MENU_STRING_ITEM, year_str[n-1], n, 0);
  1106. X    }
  1107. X}
  1108. X
  1109. X/* turn sun and moon buttons on or off */
  1110. Xsun_moon_buttons(state)
  1111. Xint state;
  1112. X{
  1113. X#ifndef NO_SUN_MOON
  1114. X    if (state) {
  1115. X        if (!mframe)
  1116. X            panel_set(moonbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1117. X        if (!sframe)
  1118. X            panel_set(sunbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1119. X    } else {
  1120. X        panel_set(moonbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
  1121. X        panel_set(sunbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
  1122. X        /* remove moon window, if it exists */
  1123. X        if (mframe) {
  1124. X            window_destroy(mframe);
  1125. X            mframe = 0;
  1126. X        }
  1127. X        /* remove sun window, if it exists */
  1128. X        if (sframe) {
  1129. X            window_destroy(sframe);
  1130. X            sframe = 0;
  1131. X        }
  1132. X    }
  1133. X#endif
  1134. X}
  1135. X
  1136. X/* turn print button on or off */
  1137. Xprint_button(state)
  1138. Xint state;
  1139. X{
  1140. X#ifndef NO_PRINTER
  1141. X/* if no printer specified then never show Print button */
  1142. X    if (state)
  1143. X        panel_set(printbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1144. X    else
  1145. X        panel_set(printbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
  1146. X#endif    /* NO_PRINTER */
  1147. X}
  1148. X
  1149. Xworking(state)
  1150. Xint state;
  1151. X{
  1152. X    /* turn "Working!" message on or off */
  1153. X    if (working_msg) {
  1154. X        if (state)
  1155. X            panel_set(working_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1156. X        else
  1157. X            panel_set(working_pi, PANEL_SHOW_ITEM, FALSE, 0);
  1158. X    }
  1159. X}
  1160. X
  1161. X/* Create and init main subwindow. */
  1162. Xcreate_main_window()
  1163. X{
  1164. X    canvas = window_create(frame, CANVAS,
  1165. X            CANVAS_FIXED_IMAGE, TRUE,
  1166. X            WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS,
  1167. X            WIN_UP_EVENTS, KEY_LEFT(5), KEY_LEFT(6),
  1168. X            KEY_LEFT(7), KEY_LEFT(8), 0,
  1169. X            WIN_CONSUME_PICK_EVENTS, WIN_NO_EVENTS,
  1170. X            WIN_MOUSE_BUTTONS, LOC_STILL, LOC_DRAG,
  1171. X            WIN_IN_TRANSIT_EVENTS, 0,
  1172. X            WIN_EVENT_PROC, mainsw_inputevent,
  1173. X            CANVAS_RETAINED, TRUE,
  1174. X            WIN_BELOW, panel,
  1175. X            WIN_ERROR_MSG, "Can't create main window.",
  1176. X            0);
  1177. X    main_pixwin = (Pixwin *) canvas_pixwin(canvas);
  1178. X    
  1179. X    window_set(canvas, WIN_CURSOR, day_cursor, 0);
  1180. X    mainsw_state = DISPLAYING_DAY;
  1181. X    day_is_open = FALSE;
  1182. X    draw_day1();  /* like draw_day(), only no future popup */
  1183. X}
  1184. X
  1185. Xget_fonts()
  1186. X{
  1187. X    char *default_ptr, fontstr[128];
  1188. X
  1189. X    /* Open normal and big font files. */
  1190. X    if (user_font)
  1191. X        /* use command line override */
  1192. X        font = pw_pfsysopen();
  1193. X    else if ((default_ptr = defaults_get_string("/CalenTool/Font", NULL, 0)) != NULL) {
  1194. X        if (*default_ptr != '/') {
  1195. X            strcpy(fontstr, "/usr/lib/fonts/fixedwidthfonts/");
  1196. X            strcat(fontstr, default_ptr);
  1197. X            if ((font = pf_open(fontstr)) == NULL)
  1198. X                font = pw_pfsysopen();
  1199. X        } else {
  1200. X            if ((font = pf_open(default_ptr)) == NULL)
  1201. X                font = pw_pfsysopen();
  1202. X        }
  1203. X    } else
  1204. X        font = pw_pfsysopen();
  1205. X    if ((default_ptr = defaults_get_string("/CalenTool/BigFont", NULL, 0)) != NULL) {
  1206. X        if (*default_ptr != '/') {
  1207. X            strcpy(fontstr, "/usr/lib/fonts/fixedwidthfonts/");
  1208. X            strcat(fontstr, default_ptr);
  1209. X            if ((bigfont = pf_open(fontstr)) == NULL)
  1210. X                bigfont = pf_open("/usr/lib/fonts/fixedwidthfonts/gallant.r.10");
  1211. X        } else {
  1212. X            if ((bigfont = pf_open(default_ptr)) == NULL)
  1213. X                bigfont = pf_open("/usr/lib/fonts/fixedwidthfonts/gallant.r.10");
  1214. X        }
  1215. X    } else
  1216. X        bigfont = pf_open("/usr/lib/fonts/fixedwidthfonts/gallant.r.10");
  1217. X    /* double check */
  1218. X    if (bigfont == NULL) {
  1219. X        err_rpt("unable to open large size font", NON_FATAL);
  1220. X        bigfont = pw_pfsysopen();
  1221. X    }
  1222. X
  1223. X    /* font for displaying time under the icon and days under moon */
  1224. X    sfont = pf_open("/usr/lib/fonts/fixedwidthfonts/screen.r.7");
  1225. X}
  1226. X
  1227. X/*
  1228. X * create popup window for future appts display
  1229. X * called when we draw a day display.
  1230. X */
  1231. Xcreate_future_popup()
  1232. X{
  1233. X    int i, p_width;
  1234. X    Panel_item item;
  1235. X    char *fappt_str, *format_appt();
  1236. X    static Panel_item fdone_pi, fkeep_pi;
  1237. X    static int cp_width, cp_x;
  1238. X
  1239. X    if (!fframe) {
  1240. X        /* create new frame and control panel */
  1241. X        fframe = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1242. X                WIN_X, ATTR_COL(12),
  1243. X                WIN_Y, slots[n_slots-4].slot_pos.top,
  1244. X                FRAME_LABEL, "Future Appointments",
  1245. X                FRAME_SHOW_LABEL, TRUE,
  1246. X                WIN_ERROR_MSG, "Can't create future frame.",
  1247. X                0);
  1248. X
  1249. X        fcpanel = window_create(fframe, PANEL, 0);
  1250. X    
  1251. X        fkeep_pi = panel_create_item(fcpanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1252. X                fkeep_proc, PANEL_LABEL_IMAGE,
  1253. X                panel_button_image(fcpanel, "Keep", 4, font),
  1254. X                PANEL_SHOW_ITEM, TRUE,
  1255. X                PANEL_ITEM_X, ATTR_COL(20),
  1256. X                PANEL_ITEM_Y, ATTR_ROW(0),
  1257. X                0);
  1258. X    
  1259. X        fdone_pi = panel_create_item(fcpanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1260. X                fdone_proc, PANEL_LABEL_IMAGE,
  1261. X                panel_button_image(fcpanel, "Done", 4, font),
  1262. X                PANEL_SHOW_ITEM, TRUE,
  1263. X                PANEL_ITEM_X, ATTR_COL(30),
  1264. X                PANEL_ITEM_Y, ATTR_ROW(0),
  1265. X                0);
  1266. X    
  1267. X        window_fit(fcpanel);
  1268. X        cp_width = (int) window_get(fcpanel, WIN_WIDTH);
  1269. X        cp_x = (int) window_get(fcpanel, WIN_X);
  1270. X
  1271. X    } else {
  1272. X        /* existing frame, so just delete and recreate the
  1273. X         * message panel and its items
  1274. X         */
  1275. X        window_destroy(fpanel);
  1276. X    }
  1277. X    fpanel = window_create(fframe, PANEL, WIN_BELOW, fcpanel,
  1278. X            WIN_FONT, font, WIN_X, cp_x, 0);
  1279. X    /* create a panel message item for each future appt */
  1280. X    for (i=0; i<findex; i++) {
  1281. X        fappt_str = format_appt(&future[i]);
  1282. X        (void) panel_create_item(fpanel, PANEL_MESSAGE,
  1283. X                PANEL_NOTIFY_PROC, fappt_notify,
  1284. X                PANEL_SHOW_ITEM, TRUE,
  1285. X                PANEL_CLIENT_DATA, (caddr_t)i,
  1286. X                PANEL_LABEL_X, ATTR_COL(1),
  1287. X                PANEL_LABEL_Y, ATTR_ROW(i),
  1288. X                PANEL_LABEL_FONT, font,
  1289. X                PANEL_LABEL_STRING, fappt_str,
  1290. X                0);
  1291. X    }
  1292. X    window_fit(fpanel);
  1293. X    /* find out which panel is wider and use it for frame width */
  1294. X    p_width = (int) window_get(fpanel, WIN_WIDTH);
  1295. X    if (p_width > cp_width) {
  1296. X        /* reset control panel size */
  1297. X        window_set(fcpanel, WIN_WIDTH, p_width, 0);
  1298. X        /* move buttons */
  1299. X        panel_set(fdone_pi, PANEL_ITEM_X, ATTR_COL(-7)+p_width,
  1300. X                PANEL_SHOW_ITEM, TRUE,
  1301. X                0);
  1302. X        panel_set(fkeep_pi, PANEL_ITEM_X, ATTR_COL(-17)+p_width,
  1303. X                PANEL_SHOW_ITEM, TRUE,
  1304. X                0);
  1305. X    } else {
  1306. X        window_set(fpanel, WIN_WIDTH, cp_width, 0);
  1307. X        /* move buttons */
  1308. X        panel_set(fdone_pi, PANEL_ITEM_X, ATTR_COL(-7)+cp_width,
  1309. X                PANEL_SHOW_ITEM, TRUE,
  1310. X                0);
  1311. X        panel_set(fkeep_pi, PANEL_ITEM_X, ATTR_COL(-17)+cp_width,
  1312. X                PANEL_SHOW_ITEM, TRUE,
  1313. X                0);
  1314. X    }
  1315. X    window_fit(fframe);
  1316. X    window_set(fframe, WIN_SHOW, TRUE, 0);
  1317. X}
  1318. X
  1319. X/*
  1320. X * create a popup to modify or set attributes for a given
  1321. X * appointment.
  1322. X */
  1323. Xcreate_attr_frame()
  1324. X{
  1325. X    void everyx_notify();
  1326. X
  1327. X    /* create new frame and control panel */
  1328. X    attr_frame = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1329. X            FRAME_SHOW_LABEL, FALSE,
  1330. X            WIN_ERROR_MSG, "Can't create attributes frame.",
  1331. X            0);
  1332. X
  1333. X    attr_panel = window_create(attr_frame, PANEL,
  1334. X            WIN_FONT, font,
  1335. X            PANEL_BLINK_CARET, TRUE,
  1336. X            0);
  1337. X    
  1338. X    (void) panel_create_item(attr_panel, PANEL_MESSAGE,
  1339. X            PANEL_SHOW_ITEM, TRUE,
  1340. X            PANEL_LABEL_STRING, "Appointment Options",
  1341. X            PANEL_LABEL_X, ATTR_COL(4),
  1342. X            PANEL_LABEL_Y, ATTR_ROW(0)+4,
  1343. X            PANEL_LABEL_BOLD, TRUE,
  1344. X            0);
  1345. X
  1346. X    (void) panel_create_item(attr_panel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1347. X            attr_accept, PANEL_LABEL_IMAGE,
  1348. X            panel_button_image(attr_panel, "Accept", 6, font),
  1349. X            PANEL_SHOW_ITEM, TRUE,
  1350. X            PANEL_ITEM_X, ATTR_COL(35),
  1351. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1352. X            0);
  1353. X
  1354. X    (void) panel_create_item(attr_panel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1355. X            attr_abort, PANEL_LABEL_IMAGE,
  1356. X            panel_button_image(attr_panel, "Abort", 5, font),
  1357. X            PANEL_SHOW_ITEM, TRUE,
  1358. X            PANEL_ITEM_X, ATTR_COL(45),
  1359. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1360. X            0);
  1361. X
  1362. X    everyx_pi = panel_create_item(attr_panel, PANEL_TOGGLE,
  1363. X            PANEL_SHOW_ITEM, TRUE,
  1364. X            PANEL_DISPLAY_LEVEL, PANEL_ALL,
  1365. X            PANEL_NOTIFY_PROC, everyx_notify,
  1366. X            PANEL_LABEL_STRING, "Repeat appointment:",
  1367. X            PANEL_CHOICE_STRINGS, "Mon-Fri", "Every Day",
  1368. X            "Selected Week", "Every Month", "Every Year", 0,
  1369. X            PANEL_ITEM_X, ATTR_COL(1),
  1370. X            PANEL_ITEM_Y, ATTR_ROW(2)-5,
  1371. X            0);
  1372. X
  1373. X    whichwk_pi = panel_create_item(attr_panel, PANEL_TOGGLE,
  1374. X            PANEL_SHOW_ITEM, TRUE,
  1375. X            PANEL_DISPLAY_LEVEL, PANEL_ALL,
  1376. X            PANEL_LABEL_STRING,
  1377. X            "Indicate which week(s) in the month:",
  1378. X            PANEL_CHOICE_STRINGS, "1st", "2nd",
  1379. X            "3rd", "4th", "5th", "Last", "All", 0,
  1380. X            PANEL_ITEM_X, ATTR_COL(1),
  1381. X            PANEL_ITEM_Y, ATTR_ROW(3)-5,
  1382. X            0);
  1383. X
  1384. X    repeat_pi = panel_create_item(attr_panel, PANEL_TEXT,
  1385. X            PANEL_SHOW_ITEM, FALSE,
  1386. X            PANEL_LABEL_STRING,
  1387. X            "Repeat at specified interval of days:",
  1388. X            PANEL_VALUE, 0, PANEL_VALUE_STORED_LENGTH, 4,
  1389. X            PANEL_VALUE_DISPLAY_LENGTH, 4,
  1390. X            PANEL_ITEM_X, ATTR_COL(1),
  1391. X            PANEL_ITEM_Y, ATTR_ROW(3),
  1392. X            PANEL_BLINK_CARET, TRUE,
  1393. X            0);
  1394. X    
  1395. X    runl_pi = panel_create_item(attr_panel, PANEL_TEXT,
  1396. X            PANEL_SHOW_ITEM, TRUE,
  1397. X            PANEL_LABEL_STRING,
  1398. X            "Repeat specified number of times (default forever):",
  1399. X            PANEL_VALUE, 0, PANEL_VALUE_STORED_LENGTH, 4,
  1400. X            PANEL_VALUE_DISPLAY_LENGTH, 4,
  1401. X            PANEL_ITEM_X, ATTR_COL(1),
  1402. X            PANEL_ITEM_Y, ATTR_ROW(4),
  1403. X            PANEL_BLINK_CARET, TRUE,
  1404. X            0);
  1405. X
  1406. X    remind_pi = panel_create_item(attr_panel, PANEL_TEXT,
  1407. X            PANEL_SHOW_ITEM, TRUE,
  1408. X            PANEL_LABEL_STRING,
  1409. X            "Warn in advance by specified number of days:",
  1410. X            PANEL_VALUE, 0, PANEL_VALUE_STORED_LENGTH, 4,
  1411. X            PANEL_VALUE_DISPLAY_LENGTH, 4,
  1412. X            PANEL_ITEM_X, ATTR_COL(1),
  1413. X            PANEL_ITEM_Y, ATTR_ROW(5),
  1414. X            PANEL_BLINK_CARET, TRUE,
  1415. X            0);
  1416. X
  1417. X    advw_pi = panel_create_item(attr_panel, PANEL_TEXT,
  1418. X            PANEL_SHOW_ITEM, TRUE,
  1419. X            PANEL_LABEL_STRING,
  1420. X            "Remind a specified number of minutes before:",
  1421. X            PANEL_VALUE, 0, PANEL_VALUE_STORED_LENGTH, 4,
  1422. X            PANEL_VALUE_DISPLAY_LENGTH, 4,
  1423. X            PANEL_ITEM_X, ATTR_COL(1),
  1424. X            PANEL_ITEM_Y, ATTR_ROW(6),
  1425. X            PANEL_BLINK_CARET, TRUE,
  1426. X            0);
  1427. X
  1428. X    /* This panel item is currently only supported
  1429. X     * for note appointment entries.
  1430. X     */
  1431. X    marked_pi = panel_create_item(attr_panel, PANEL_CYCLE,
  1432. X            PANEL_SHOW_ITEM, FALSE,
  1433. X            PANEL_LABEL_STRING,
  1434. X            "Mark in month/year display:",
  1435. X            PANEL_CHOICE_STRINGS, "Yes", "No", 0,
  1436. X            PANEL_ITEM_X, ATTR_COL(1),
  1437. X            PANEL_ITEM_Y, ATTR_ROW(7),
  1438. X            0);
  1439. X
  1440. X    window_fit(attr_panel);
  1441. X    window_fit(attr_frame);
  1442. X}
  1443. X
  1444. X/*
  1445. X * create a popup to choose delete mode
  1446. X */
  1447. Xcreate_del_frame()
  1448. X{
  1449. X    /* create new frame and control panel */
  1450. X    del_frame = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1451. X            FRAME_SHOW_LABEL, FALSE,
  1452. X            WIN_ERROR_MSG, "Can't create delete frame.",
  1453. X            0);
  1454. X
  1455. X    del_panel = window_create(del_frame, PANEL,
  1456. X            WIN_FONT, font,
  1457. X            0);
  1458. X    
  1459. X    (void) panel_create_item(del_panel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1460. X            del_done, PANEL_LABEL_IMAGE,
  1461. X            panel_button_image(del_panel, "Accept", 6, font),
  1462. X            PANEL_SHOW_ITEM, TRUE,
  1463. X            PANEL_ITEM_X, ATTR_COL(30),
  1464. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1465. X            0);
  1466. X
  1467. X    (void) panel_create_item(del_panel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1468. X            attr_abort, PANEL_LABEL_IMAGE,
  1469. X            panel_button_image(del_panel, "Abort", 5, font),
  1470. X            PANEL_SHOW_ITEM, TRUE,
  1471. X            PANEL_ITEM_X, ATTR_COL(40),
  1472. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1473. X            0);
  1474. X
  1475. X    (void) panel_create_item(del_panel, PANEL_MESSAGE,
  1476. X            PANEL_SHOW_ITEM, TRUE,
  1477. X            PANEL_LABEL_STRING, "This is a recurring appointment.",
  1478. X            PANEL_LABEL_X, ATTR_COL(1),
  1479. X            PANEL_LABEL_Y, ATTR_ROW(1)+5,
  1480. X            PANEL_LABEL_BOLD, TRUE,
  1481. X            0);
  1482. X
  1483. X    del_choice_pi = panel_create_item(del_panel, PANEL_CYCLE,
  1484. X            PANEL_SHOW_ITEM, TRUE,
  1485. X            PANEL_LABEL_STRING, "Do you wish to:",
  1486. X            PANEL_CHOICE_STRINGS, "Delete this occurrance only", "Delete all occurrances", 0,
  1487. X            PANEL_ITEM_X, ATTR_COL(1),
  1488. X            PANEL_ITEM_Y, ATTR_ROW(2)+5,
  1489. X            0);
  1490. X
  1491. X    window_fit(del_panel);
  1492. X    window_fit(del_frame);
  1493. X}
  1494. X
  1495. X#ifndef NO_SUN_MOON
  1496. X/*
  1497. X * create popup for sun data frame
  1498. X */
  1499. Xsun_data_frame()
  1500. X{
  1501. X    Panel spanel;
  1502. X
  1503. X    /* create new frame and canvas */
  1504. X    if (!sframe) {
  1505. X        sframe = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1506. X                WIN_X, ATTR_COL(12),
  1507. X                FRAME_LABEL, "Solar Data",
  1508. X                FRAME_SHOW_LABEL, TRUE,
  1509. X                FRAME_DONE_PROC, sframe_done,
  1510. X                WIN_ERROR_MSG, "Can't create sun data frame.",
  1511. X                0);
  1512. X
  1513. X        spanel = window_create(sframe, PANEL, WIN_FONT, font,
  1514. X                WIN_WIDTH, 55*font->pf_defaultsize.x,
  1515. X                WIN_ERROR_MSG, "Can't create sun data panel.",
  1516. X                0);
  1517. X    
  1518. X        (void) panel_create_item(spanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1519. X                sdone_proc, PANEL_LABEL_IMAGE,
  1520. X                panel_button_image(spanel, "Done", 4, font),
  1521. X                PANEL_SHOW_ITEM, TRUE,
  1522. X                PANEL_ITEM_X, ATTR_COL(45),
  1523. X                PANEL_ITEM_Y, ATTR_ROW(0),
  1524. X                0);
  1525. X
  1526. X        sdate_pi = panel_create_item(spanel, PANEL_MESSAGE,
  1527. X                PANEL_ITEM_X, ATTR_COL(8),
  1528. X                PANEL_ITEM_Y, ATTR_ROW(0),
  1529. X                /* string filled in later */
  1530. X                PANEL_LABEL_STRING, "",
  1531. X                PANEL_LABEL_FONT, font,
  1532. X                0);
  1533. X    
  1534. X        window_fit_height(spanel);
  1535. X        scanvas = window_create(sframe, CANVAS, WIN_BELOW, spanel,
  1536. X                WIN_X, 0,
  1537. X                WIN_HEIGHT, 17*font->pf_defaultsize.y,
  1538. X                WIN_CONSUME_PICK_EVENT, WIN_NO_EVENTS,
  1539. X                WIN_CONSUME_KBD_EVENT, WIN_NO_EVENTS,
  1540. X                WIN_ERROR_MSG, "Can't create sun data canvas.",
  1541. X                0);
  1542. X    
  1543. X        write_sun_data();
  1544. X        window_fit(sframe);
  1545. X        window_set(sframe, WIN_SHOW, TRUE, 0);
  1546. X    } else
  1547. X        write_sun_data();
  1548. X}
  1549. X
  1550. X/*
  1551. X * create popup for moon data frame
  1552. X */
  1553. Xmoon_data_frame()
  1554. X{
  1555. X    Panel mpanel;
  1556. X
  1557. X    /* create new frame and canvas */
  1558. X    if (!mframe) {
  1559. X        mframe = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1560. X                WIN_X, ATTR_COL(12),
  1561. X                FRAME_LABEL, "Lunar Data",
  1562. X                FRAME_SHOW_LABEL, TRUE,
  1563. X                FRAME_FOREGROUND_COLOR, &fg_default,
  1564. X                FRAME_BACKGROUND_COLOR, &bg_default,
  1565. X                FRAME_DONE_PROC, mframe_done,
  1566. X                WIN_ERROR_MSG, "Can't create moon data frame.",
  1567. X                0);
  1568. X
  1569. X        mpanel = window_create(mframe, PANEL, WIN_FONT, font,
  1570. X                WIN_WIDTH, 70*font->pf_defaultsize.x,
  1571. X                WIN_ERROR_MSG, "Can't create moon data panel.",
  1572. X                0);
  1573. X    
  1574. X        (void) panel_create_item(mpanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1575. X                mdone_proc, PANEL_LABEL_IMAGE,
  1576. X                panel_button_image(mpanel, "Done", 4, font),
  1577. X                PANEL_SHOW_ITEM, TRUE,
  1578. X                PANEL_ITEM_X, ATTR_COL(60),
  1579. X                PANEL_ITEM_Y, ATTR_ROW(0),
  1580. X                0);
  1581. X
  1582. X        mdate_pi = panel_create_item(mpanel, PANEL_MESSAGE,
  1583. X                PANEL_ITEM_X, ATTR_COL(8),
  1584. X                PANEL_ITEM_Y, ATTR_ROW(0),
  1585. X                /* string filled in later */
  1586. X                PANEL_LABEL_STRING, "",
  1587. X                PANEL_LABEL_FONT, font,
  1588. X                0);
  1589. X    
  1590. X        window_fit_height(mpanel);
  1591. X        mcanvas = window_create(mframe, CANVAS, WIN_BELOW, mpanel,
  1592. X                WIN_X, 0,
  1593. X                WIN_HEIGHT, 17*font->pf_defaultsize.y,
  1594. X                CANVAS_RETAINED, TRUE,
  1595. X                WIN_CONSUME_PICK_EVENT, WIN_NO_EVENTS,
  1596. X                WIN_CONSUME_KBD_EVENT, WIN_NO_EVENTS,
  1597. X                WIN_ERROR_MSG, "Can't create moon data canvas.",
  1598. X                0);
  1599. X    
  1600. X        write_moon_data();
  1601. X        window_fit(mframe);
  1602. X        window_set(mframe, WIN_SHOW, TRUE, 0);
  1603. X    } else
  1604. X        write_moon_data();
  1605. X}
  1606. X#endif    /* NO_SUN_MOON */
  1607. X
  1608. X/*
  1609. X * create a popup to allow selecting a different appointment file
  1610. X */
  1611. Xcreate_file_frame()
  1612. X{
  1613. X
  1614. X    /* create new frame and control panel */
  1615. X    fileframe = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1616. X            FRAME_LABEL, "File Selection",
  1617. X            FRAME_SHOW_LABEL, TRUE,
  1618. X            FRAME_DONE_PROC, fileframe_done,
  1619. X            WIN_ERROR_MSG, "Can't create file frame.",
  1620. X            0);
  1621. X
  1622. X    filepanel = window_create(fileframe, PANEL, WIN_FONT, font,
  1623. X            PANEL_BLINK_CARET, TRUE,
  1624. X            0);
  1625. X    
  1626. X    file_ro_pi = panel_create_item(filepanel, PANEL_CYCLE, PANEL_CHOICE_STRINGS,
  1627. X            "Read Only", "Read/Write", 0,
  1628. X            PANEL_SHOW_ITEM, TRUE,
  1629. X            PANEL_ITEM_X, ATTR_COL(1),
  1630. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1631. X            0);
  1632. X
  1633. X    (void) panel_create_item(filepanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1634. X            file_orig, PANEL_LABEL_IMAGE,
  1635. X            panel_button_image(filepanel, "Original", 7, font),
  1636. X            PANEL_SHOW_ITEM, TRUE,
  1637. X            PANEL_ITEM_X, ATTR_COL(17),
  1638. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1639. X            0);
  1640. X
  1641. X    (void) panel_create_item(filepanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1642. X            file_accept, PANEL_LABEL_IMAGE,
  1643. X            panel_button_image(filepanel, "Accept", 6, font),
  1644. X            PANEL_SHOW_ITEM, TRUE,
  1645. X            PANEL_ITEM_X, ATTR_COL(27),
  1646. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1647. X            0);
  1648. X
  1649. X    (void) panel_create_item(filepanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1650. X            file_reset, PANEL_LABEL_IMAGE,
  1651. X            panel_button_image(filepanel, "Reset", 5, font),
  1652. X            PANEL_SHOW_ITEM, TRUE,
  1653. X            PANEL_ITEM_X, ATTR_COL(35),
  1654. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1655. X            0);
  1656. X
  1657. X    (void) panel_create_item(filepanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1658. X            file_save, PANEL_LABEL_IMAGE,
  1659. X            panel_button_image(filepanel, "Update", 6, font),
  1660. X            PANEL_SHOW_ITEM, TRUE,
  1661. X            PANEL_ITEM_X, ATTR_COL(42),
  1662. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1663. X            0);
  1664. X
  1665. X    (void) panel_create_item(filepanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1666. X            file_done, PANEL_LABEL_IMAGE,
  1667. X            panel_button_image(filepanel, "Done", 4, font),
  1668. X            PANEL_SHOW_ITEM, TRUE,
  1669. X            PANEL_ITEM_X, ATTR_COL(50),
  1670. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1671. X            0);
  1672. X
  1673. X    (void) panel_create_item(filepanel, PANEL_MESSAGE,
  1674. X            PANEL_SHOW_ITEM, TRUE,
  1675. X            PANEL_LABEL_STRING, "Enter the desired appointment file",
  1676. X            PANEL_LABEL_X, ATTR_COL(6),
  1677. X            PANEL_LABEL_Y, ATTR_ROW(2),
  1678. X            PANEL_LABEL_BOLD, TRUE,
  1679. X            0);
  1680. X
  1681. X    filename_pi = panel_create_item(filepanel, PANEL_TEXT,
  1682. X            PANEL_SHOW_ITEM, TRUE,
  1683. X            PANEL_LABEL_STRING, "Filename:",
  1684. X            PANEL_LABEL_BOLD, TRUE,
  1685. X            PANEL_VALUE, 0, PANEL_VALUE_STORED_LENGTH, 128,
  1686. X            PANEL_VALUE_DISPLAY_LENGTH, 30,
  1687. X            PANEL_ITEM_X, ATTR_COL(1),
  1688. X            PANEL_ITEM_Y, ATTR_ROW(3),
  1689. X            PANEL_BLINK_CARET, TRUE,
  1690. X            0);
  1691. X
  1692. X    window_fit(filepanel);
  1693. X    window_fit(fileframe);
  1694. X}
  1695. X
  1696. X/*
  1697. X * create a popup to display an error message
  1698. X */
  1699. Xcreate_prompt_frame(str1, buttonflag)
  1700. Xchar *str1;
  1701. X{
  1702. X    static Panel_item prompt_panel;
  1703. X    static Panel_item msg_pi, yes_pi, no_pi = 0;
  1704. X
  1705. X    if (!prompt_frame) {
  1706. X        /* create new frame and control panel */
  1707. X        prompt_frame = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1708. X                FRAME_SHOW_LABEL, FALSE,
  1709. X                WIN_SHOW, TRUE,
  1710. X                WIN_X, ATTR_COL(15), WIN_Y, ATTR_ROW(15),
  1711. X                WIN_ERROR_MSG, "Can't create error frame.",
  1712. X                0);
  1713. X
  1714. X        prompt_panel = window_create(prompt_frame, PANEL,
  1715. X                PANEL_ACCEPT_KEYSTROKE, FALSE,
  1716. X                WIN_FONT, font,
  1717. X                0);
  1718. X    } else {
  1719. X        /* existing frame, delete the items */
  1720. X        panel_destroy_item(msg_pi);
  1721. X        panel_destroy_item(yes_pi);
  1722. X        if (no_pi) {
  1723. X            panel_destroy_item(no_pi);
  1724. X            no_pi = 0;
  1725. X        }
  1726. X    }
  1727. X    
  1728. X    /* create new message and button panel items */
  1729. X    msg_pi = panel_create_item(prompt_panel, PANEL_MESSAGE,
  1730. X            PANEL_SHOW_ITEM, TRUE,
  1731. X            PANEL_ITEM_X, ATTR_COL(1),
  1732. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1733. X            PANEL_LABEL_STRING, str1,
  1734. X            PANEL_LABEL_BOLD, TRUE,
  1735. X            0);
  1736. X
  1737. X    if (buttonflag) {
  1738. X        yes_pi = panel_create_item(prompt_panel, PANEL_BUTTON,
  1739. X                PANEL_SHOW_ITEM, TRUE,
  1740. X                PANEL_ITEM_X, ATTR_COL(4),
  1741. X                PANEL_ITEM_Y, ATTR_ROW(2),
  1742. X                PANEL_NOTIFY_PROC, prompt_yes_notify,
  1743. X                PANEL_LABEL_IMAGE,
  1744. X                panel_button_image(prompt_panel, "Yes", 3, font),
  1745. X                0);
  1746. X
  1747. X        no_pi = panel_create_item(prompt_panel, PANEL_MESSAGE,
  1748. X                PANEL_SHOW_ITEM, TRUE,
  1749. X                PANEL_ITEM_X, ATTR_COL(12),
  1750. X                PANEL_ITEM_Y, ATTR_ROW(2),
  1751. X                PANEL_NOTIFY_PROC, prompt_no_notify,
  1752. X                PANEL_LABEL_IMAGE,
  1753. X                panel_button_image(prompt_panel, "No", 2, font),
  1754. X                0);
  1755. X    } else {
  1756. X        yes_pi = panel_create_item(prompt_panel, PANEL_MESSAGE,
  1757. X                PANEL_SHOW_ITEM, TRUE,
  1758. X                PANEL_ITEM_X, ATTR_COL(12),
  1759. X                PANEL_ITEM_Y, ATTR_ROW(2),
  1760. X                PANEL_NOTIFY_PROC, prompt_yes_notify,
  1761. X                PANEL_LABEL_IMAGE,
  1762. X                panel_button_image(prompt_panel, "Ok", 2, font),
  1763. X                0);
  1764. X    }
  1765. X
  1766. X    window_fit(prompt_panel);
  1767. X    window_fit(prompt_frame);
  1768. X}
  1769. X
  1770. X#ifndef NO_PRINTER
  1771. X/* create popup to change the printer */
  1772. Xcreate_print_frame()
  1773. X{
  1774. X    Panel prpanel;
  1775. X
  1776. X    prframe = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1777. X            WIN_SHOW, FALSE, WIN_X, ATTR_COL(12),
  1778. X            FRAME_LABEL, "Change Printer",
  1779. X            FRAME_SHOW_LABEL, TRUE,
  1780. X            FRAME_DONE_PROC, prframe_done,
  1781. X            WIN_ERROR_MSG, "Can't create printer frame.",
  1782. X            0);
  1783. X
  1784. X    prpanel = window_create(prframe, PANEL, WIN_FONT, font,
  1785. X            WIN_ERROR_MSG, "Can't create printer panel.",
  1786. X            0);
  1787. X    
  1788. X    (void) panel_create_item(prpanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1789. X            prdone_proc, PANEL_LABEL_IMAGE,
  1790. X            panel_button_image(prpanel, "Done", 4, font),
  1791. X            PANEL_SHOW_ITEM, TRUE,
  1792. X            PANEL_ITEM_X, ATTR_COL(34),
  1793. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1794. X            0);
  1795. X
  1796. X    prfile_pi = panel_create_item(prpanel, PANEL_CYCLE,
  1797. X            PANEL_SHOW_ITEM, TRUE,
  1798. X            PANEL_ITEM_X, ATTR_COL(1),
  1799. X            PANEL_ITEM_Y, ATTR_ROW(1)+5,
  1800. X            PANEL_LABEL_STRING, "Destination:",
  1801. X            PANEL_LABEL_BOLD, TRUE,
  1802. X            PANEL_CHOICE_STRINGS, "Printer", "File Only", 0,
  1803. X            0);
  1804. X    
  1805. X    prcmd_pi = panel_create_item(prpanel, PANEL_TEXT,
  1806. X            PANEL_SHOW_ITEM, TRUE,
  1807. X            PANEL_ITEM_X, ATTR_COL(1),
  1808. X            PANEL_ITEM_Y, ATTR_ROW(2)+5,
  1809. X            PANEL_LABEL_STRING, "Print command:",
  1810. X            PANEL_LABEL_FONT, font,
  1811. X            PANEL_LABEL_BOLD, TRUE,
  1812. X            PANEL_VALUE_STORED_LENGTH, 128,
  1813. X            PANEL_VALUE_DISPLAY_LENGTH, 30,
  1814. X            PANEL_BLINK_CARET, TRUE,
  1815. X            0);
  1816. X    
  1817. X    panel_set_value(prcmd_pi, printer);
  1818. X    panel_set_value(prfile_pi, 0);
  1819. X    window_fit(prpanel);
  1820. X    window_fit(prframe);
  1821. X}
  1822. X#endif    /* NO_PRINTER */
  1823. X
  1824. X/* create popup to change the date */
  1825. Xcreate_date_frame()
  1826. X{
  1827. X    Panel dtpanel;
  1828. X    char date[9];
  1829. X
  1830. X    date_frame = window_create(frame, FRAME, FRAME_NO_CONFIRM, TRUE,
  1831. X            WIN_SHOW, FALSE, WIN_X, ATTR_COL(12),
  1832. X            FRAME_LABEL, "Change Current Date",
  1833. X            FRAME_SHOW_LABEL, TRUE,
  1834. X            FRAME_DONE_PROC, dtframe_done,
  1835. X            WIN_ERROR_MSG, "Can't create date frame.",
  1836. X            0);
  1837. X
  1838. X    dtpanel = window_create(date_frame, PANEL, WIN_FONT, font,
  1839. X            WIN_ERROR_MSG, "Can't create date panel.",
  1840. X            0);
  1841. X    
  1842. X    (void) panel_create_item(dtpanel, PANEL_BUTTON, PANEL_NOTIFY_PROC,
  1843. X            dtdone_proc, PANEL_LABEL_IMAGE,
  1844. X            panel_button_image(dtpanel, "Done", 4, font),
  1845. X            PANEL_SHOW_ITEM, TRUE,
  1846. X            PANEL_ITEM_X, ATTR_COL(34),
  1847. X            PANEL_ITEM_Y, ATTR_ROW(0),
  1848. X            0);
  1849. X
  1850. X    setdate_pi = panel_create_item(dtpanel, PANEL_TEXT,
  1851. X            PANEL_SHOW_ITEM, TRUE,
  1852. X            PANEL_ITEM_X, ATTR_COL(1),
  1853. X            PANEL_ITEM_Y, ATTR_ROW(1)+5,
  1854. X            PANEL_LABEL_STRING, (day_first ? "Enter date (D, D/M, or D/M/Y):" : "Enter date (D, M/D, or M/D/Y):"),
  1855. X            PANEL_LABEL_FONT, font,
  1856. X            PANEL_LABEL_BOLD, TRUE,
  1857. X            PANEL_VALUE_STORED_LENGTH, 10,
  1858. X            PANEL_VALUE_DISPLAY_LENGTH, 10,
  1859. X            PANEL_BLINK_CARET, TRUE,
  1860. X            0);
  1861. X    
  1862. X    if (day_first)
  1863. X        sprintf(date, "%d/%d/%02d", current.tm_mday, current.tm_mon+1, current.tm_year);
  1864. X    else
  1865. X        sprintf(date, "%d/%d/%02d", current.tm_mon+1, current.tm_mday, current.tm_year);
  1866. X    panel_set_value(setdate_pi, date);
  1867. X    window_fit(dtpanel);
  1868. X    window_fit(date_frame);
  1869. X}
  1870. X
  1871. X/* replace cursors with hourglass symbol to show we're waiting */
  1872. Xlock_cursors()
  1873. X{
  1874. X    panel_cursor = cursor_copy((Cursor) window_get(panel, WIN_CURSOR));
  1875. X    canvas_cursor = cursor_copy((Cursor) window_get(canvas, WIN_CURSOR));
  1876. X    window_set(panel, WIN_CURSOR, wait_cursor, 0);
  1877. X    window_set(canvas, WIN_CURSOR, wait_cursor, 0);
  1878. X    locked = 1;
  1879. X}
  1880. X
  1881. X/* restore cursors */
  1882. Xunlock_cursors()
  1883. X{
  1884. X    window_set(panel, WIN_CURSOR, panel_cursor, 0);
  1885. X    window_set(canvas, WIN_CURSOR, canvas_cursor, 0);
  1886. X    cursor_destroy(panel_cursor);
  1887. X    cursor_destroy(canvas_cursor);
  1888. X    locked = 0;
  1889. X}
  1890. END_OF_FILE
  1891. if test 33530 -ne `wc -c <'tool.c'`; then
  1892.     echo shar: \"'tool.c'\" unpacked with wrong size!
  1893. fi
  1894. # end of 'tool.c'
  1895. fi
  1896. echo shar: End of archive 11 \(of 23\).
  1897. cp /dev/null ark11isdone
  1898. MISSING=""
  1899. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ; do
  1900.     if test ! -f ark${I}isdone ; then
  1901.     MISSING="${MISSING} ${I}"
  1902.     fi
  1903. done
  1904. if test "${MISSING}" = "" ; then
  1905.     echo You have unpacked all 23 archives.
  1906.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1907. else
  1908.     echo You still need to unpack the following archives:
  1909.     echo "        " ${MISSING}
  1910. fi
  1911. ##  End of shell archive.
  1912. exit 0
  1913.  
  1914. exit 0 # Just in case...
  1915. -- 
  1916. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1917. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1918. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1919. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1920.